package com.chandra.pos;

import com.chandra.pos.common.dao.AbstractAuditableEntity;
import com.chandra.pos.common.model.POSConstant;
import com.chandra.pos.common.utils.DateUtils;
import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;


import org.springframework.data.domain.Sort;
import org.springframework.format.annotation.DateTimeFormat;


/**
 * Created by Admin on 3/16/15.
 */
public class PosFilter extends AbstractAuditableEntity {

    protected int rows = 10;
    protected int page = 1;

    protected String sord;
    protected String sidx;

    protected String query;

    @DateTimeFormat(pattern = POSConstant.APP_DATE_FORMAT)
    private DateTime fromDate;

    @DateTimeFormat(pattern = POSConstant.APP_DATE_FORMAT)
    private DateTime toDate;

    private Long id;


    private String dateRange;

    public String getDateRange() {
        return dateRange;
    }

    public void setDateRange(String dateRange) {
        this.dateRange = dateRange;

        if(StringUtils.isNotEmpty(dateRange) && dateRange.length() ==44){
            String fromDateString=  dateRange.substring(0,20);
            String toDateString=  dateRange.substring(24,44);


            this.fromDate = DateUtils.format(fromDateString);
            this.toDate = DateUtils.format(toDateString);

        }




    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        if(page<=0)
            this.page=1;
        else
        this.page = page;
    }

    public String getSord() {
        return sord;
    }

    public void setSord(String sord) {
        this.sord = sord;
    }


    public Sort.Direction getDBSord() {

        if ("asc".equals(sord))
            return Sort.Direction.ASC;

        else
            return Sort.Direction.DESC;

    }

    public String getSidx() {
        return sidx;
    }

    public void setSidx(String sidx) {
        this.sidx = sidx;
    }

    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public PosFilter(String sord, String sidx) {
        this.sord = sord;
        this.sidx = sidx;
    }

    public PosFilter() {

    }

    public DateTime getFromDate() {
        return fromDate;
    }

    public void setFromDate(DateTime fromDate) {
        this.fromDate = fromDate;
    }

    public DateTime getToDate() {
        return toDate;
    }

    public void setToDate(DateTime toDate) {
        this.toDate = toDate;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
}
